<!DOCTYPE html>
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <link rel="StyleSheet" type="text/css" href="/tpa/admin.css" />
   <link rel="StyleSheet" type="text/css" href="/tpa/jquery-ui.css" />
   <script type="text/javascript" src="/lib/js/jquery.js"></script>
   <script type="text/javascript" src="/lib/js/jquery.ui.js"></script>
   <script type="text/javascript" src="/lib/js/meccano.js"></script>
</head>
<body>
   <div align="center">
      <div style="margin-top: 50px; width: 400px;">
         
         <input type="button" value=" {%$TR->search->index_site%} " onclick="location.href = '/admin/search.html?reindex=1'" style="margin-right: 15px;" />
         {%if $reindexed%}
            <p>{%$TR->search->indexed%}: {%$reindexed%} {%$TR->meccano->ofarticles%}</p>
            {%if $interupted%}<p>Interupted article ID: {%$interupted%}</p>{%/if%}
         {%/if%}
         
         {%if $authorizedUser->id eq 1%}
         <form action="/admin/search.html" method="post">
            <br /><br />
            <h3>{%$TR->search->indexed_fields%}:</h3>
            <div style="margin-top: 20px;" id="search_params" style="text-align:left;" align="left">

               <input type="checkbox" name="f_title" value="1" id="f_title"{%if $data.title%} checked="checked"{%/if%} />
               <label for="f_title">- {%$TR->fields->title%}</label><br />

               <input type="checkbox" name="f_description" value="1" id="f_description"{%if $data.description%} checked="checked"{%/if%} />
               <label for="f_description">- {%$TR->fields->description%}</label><br />

               <input type="checkbox" name="f_body" value="1" id="f_body"{%if $data.body%} checked="checked"{%/if%} />
               <label for="f_body">- {%$TR->fields->body%}</label><br />

               <input type="checkbox" name="f_category" value="1" id="f_category"{%if $data.category%} checked="checked"{%/if%} onchange="categoriesSearch.switchField(this.checked)" />
               <label for="f_category">- {%$TR->datatypes->category%}</label><br />

               <div id="f_category_params" style="display:none;">
                  <a href="javascript:void(0)" onclick="categoriesSearch.addCategory(false);" class="a_icon i_add">{%$TR->meccano->addcategory%}</a>
               </div>

               <div style="padding-top: 10px;">
                  <input type="submit" name="commit" value=" {%$TR->meccano->save%} " />
               </div>
            </div>
         </form>
         {%/if%}
      </div>
   </div>


   {%if $authorizedUser->id eq 1%}
   <script type="text/javascript">
      {%if $data.category%}
      $(document).ready(function(){categoriesSearch.enable();});
      {%/if%}
      var categoriesSearch = {
         fieldId     : '#f_category',
         containerId : '#f_category_params',
         categories  : {{%if $data.category%}{%foreach from=$data.category key='k' item='v' name='i'%}{%$k%}:'{%$v|escape:"javascript"%}'{%if !$smarty.foreach.i.last%},{%/if%}{%/foreach%}{%/if%}},
         allField    : '<div class="fieldset" id="f_category_all">' +
                       '<input type="hidden" name="f_category_params[]" value="all" />' +
                       '<img src="/tpa/img/16/document_arrow.png" style="margin-right: 15px;" height="16" width="16" />' +
                       '{%$TR->meccano->allcategories|escape:"javascript"%}' +
                       '<div class="fl-right">' +
                       '<a href="javascript:void(0)" onclick="categoriesSearch.del(this);" class="a_icon i_delete">{%$TR->meccano->delete%}</a>' +
                       '</div>' +
                       '<div class="clear"></div>' +
                       '</div>',
         switchField: function(f)
         {
            if(f)
               this.enable();
            else
               this.disable();
         },
         enable: function()
         {
            if(this.categories)
            {
               for(var x in this.categories)
               {
                  this.addCategory(x);
               }
               $(this.containerId).show();
            } else
            {
               $(this.containerId).append(this.allField).show();
            }
         },
         disable: function()
         {
            $(this.containerId+' div.fieldset').remove();
            $(this.containerId).hide();
            $(this.fieldId).attr('checked', false);
         },
         addCategory: function(id)
         {
            var html = '<div class="fieldset"'+ (id ? 'id="f_category_501"' : '') +'>'+
                       (id ? '' : '{%$TR->datatypes->category|escape:"javascript"%} (ID, Alias): ') +
                       '<input type="'+ (id ? 'hidden"' : 'text" style="width:150px;"') +
                       ' name="f_category_params[]" value="'+ (id ? id : '') +'" />' +
                       (id ? '<img src="/tpa/img/16/document_arrow.png" style="margin-right: 15px;" height="16" width="16" />' : '') +
                       (id ? this.categories[id] : '') +
                       '<div class="fl-right"><a href="javascript:void(0)" onclick="categoriesSearch.del(this);" class="a_icon i_delete">{%$TR->meccano->delete|escape:"javascript"%}</a>' +
                       '</div><div class="clear"></div></div>';
            $(this.containerId).append(html);
         },
         del: function(e)
         {
            if($(this.containerId+' div.fieldset').size() == 1)
               this.disable();
            else
            {
               while(e.className != 'fieldset') e = e.parentNode;
               $(e).remove();
            }
         }
      };
   </script>
   {%/if%}
</body>
</html>